<?php
	//digunakan untuk kelas untuk permintaan yang tidak biasa
	class BIRD_MODEL extends CI_Model{
		var $temp =0;
		/**
		*	@param Pigeon, 
		*	I:	intid_week,
		*	O:	query->result
		* 	Desc: untuk melihat laporan totalomset per-week dari seluruh cabang
		*/
		function Pigeon($week){
		
			/*
			$query = $this->db->query('SELECT *,
				(select sum(n.inttotal_omset) totalomset from nota n where n.intid_cabang = c.intid_cabang and n.intid_week = "$week") totalomset 
				from cabang c
				where c.intid_cabang !="" and c.intid_cabang != 1');
			return $query->result();
			/*
			select sum(n.inttotal_omset) from nota n where n.intid_cabang = c.intid_cabang  
			*/
			$query = $this->db->query('SELECT strnama_cabang,
				(select sum(n.inttotal_omset)as totalomset from nota n where n.intid_cabang = c.intid_cabang and n.intid_week = "'.$week.'") totalomset 
				from cabang c
				where c.intid_cabang !="" and c.intid_cabang != 1');
			return $query->result();
			
		}
		/**
		*	@param WoodPecker, 
		*	I:	intid_week,
		*	O:	query->result
		* 	Desc: untuk melihat laporan semua omset per-week dari seluruh cabang
		*
		function WoodPecker($week){
		//////isinya sma dengan sales mingguan tapi semua cabang dimunculin.
		$this->temp = 'select
				(SELECT SUM(nota.inttotal_omset) FROM nota
				WHERE nota.intid_cabang = c.intid_cabang  
				and nota.intid_week = "'.$week.'") inttotal_omset,
				(SELECT SUM(nota.intomset10) FROM nota
				WHERE nota.intid_jpenjualan != 5 
				AND nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.intid_week = "'.$week.'") intomset10,
				(SELECT SUM(nota.intomset20) FROM nota
				WHERE nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.intid_week = "'.$week.'") intomset20,
				(SELECT SUM(nota_detail.intquantity*nota_detail.intharga) 
				FROM nota INNER JOIN nota_detail ON nota.intid_nota = nota_detail.intid_nota INNER JOIN barang ON nota_detail.intid_barang = barang.intid_barang
				WHERE nota.intid_week = "'.$week.'"
				AND nota.intid_cabang = c.intid_cabang
				AND nota.intid_cabang != 1
				AND (nota.intid_jpenjualan = 5 OR nota.intid_jpenjualan = 7)) omsetnetto, 
				(SELECT SUM(nota_detail.intquantity*nota_detail.intharga) 
				FROM nota INNER JOIN nota_detail ON nota.intid_nota = nota_detail.intid_nota INNER JOIN barang ON nota_detail.intid_barang = barang.intid_barang
				WHERE nota.intid_week = "'.$week.'"
				AND nota.intid_cabang = c.intid_cabang
				AND nota.intid_cabang != 1
				AND nota.intid_jpenjualan = 11) omsetspecialprice,
				(SELECT SUM(nota_detail.intquantity*nota_detail.intharga) 
				FROM nota INNER JOIN nota_detail ON nota.intid_nota = nota_detail.intid_nota INNER JOIN barang ON nota_detail.intid_barang = barang.intid_barang
				WHERE nota.intid_week = "'.$week.'"
				AND nota.intid_cabang = c.intid_cabang
				AND nota.intid_jpenjualan = 12) omsetpoint,
				(SELECT sum(nota.inttotal_bayar) 
				FROM nota INNER JOIN nota_detail ON nota.intid_nota = nota_detail.intid_nota INNER JOIN barang ON nota_detail.intid_barang = barang.intid_barang
				WHERE nota.intid_week = "'.$week.'"
				AND nota.intid_cabang = c.intid_cabang
				AND nota.intid_jpenjualan = 10) omsetsk,
				(select sum(nota_detail.intquantity*nota_detail.intharga) 
				from nota, nota_detail, barang 
				where nota.intid_nota = nota_detail.intid_nota
				and nota_detail.intid_barang = barang.intid_barang
				and nota.intid_week = "'.$week.'"
				and nota.intid_cabang = c.intid_cabang
				and nota.is_arisan = 0
				and nota.is_dp = 0
				and barang.intid_jbarang=5) omsetlg,
				(select sum(nota_detail.intquantity*nota_detail.intharga) 
				from nota, nota_detail, barang 
				where nota.intid_nota = nota_detail.intid_nota
				and nota_detail.intid_barang = barang.intid_barang
				and nota.intid_week = "'.$week.'"
				and nota.intid_cabang = c.intid_cabang
				and barang.intid_jbarang=6
				and nota.is_arisan = 0
				and nota.is_dp = 0) omsetll,
				(select sum(inttotal_bayar) from nota where 
				nota.intid_cabang = c.intid_cabang
				and nota.intid_week = "'.$week.'") inttotal_bayar,
				(select sum(intpv) from nota where 
				nota.intid_cabang = c.intid_cabang
				and nota.intid_week = "'.$week.'") intpv,
			c.strnama_cabang 
			from cabang c';
		$query = $this->db->query($this->temp);
	return $query->result();
		}
		*/
		/**
		*	@param WoodPecker, 
		*	I:	intid_week,
		*	O:	query->result
		* 	Desc: untuk melihat laporan semua omset per-week dari seluruh cabang
		*/
		function WoodPecker($week){
		//////isinya sma dengan sales mingguan tapi semua cabang dimunculin.
		$this->temp = 'select
				(SELECT SUM(nota.inttotal_omset) FROM nota
				WHERE nota.intid_cabang = c.intid_cabang  
				and nota.intid_week = "'.$week.'") inttotal_omset,
				(SELECT SUM(nota.intomset10) FROM nota
				WHERE nota.intid_jpenjualan != 5 
				AND nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.intid_week = "'.$week.'"
				and nota.is_arisan != 1 
				and nota.intid_jpenjualan = 1 ) intomset10Reguler,
				(SELECT SUM(nota.intomset20) FROM nota
				WHERE nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.intid_week = "'.$week.'"
				and nota.is_arisan != 1 
				and nota.intid_jpenjualan = 1)intomset20Reguler,
				(SELECT SUM(nota.intomset10) FROM nota
				WHERE nota.intid_jpenjualan != 5 
				AND nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.intid_week = "'.$week.'"
				and nota.is_arisan = 1 
				and nota.intid_jpenjualan = 1 ) intomset10Arisan,
				(SELECT SUM(nota.intomset20) FROM nota
				WHERE nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.intid_week = "'.$week.'"
				and nota.is_arisan = 1 
				and nota.intid_jpenjualan = 1)intomset20Arisan,
				(SELECT SUM(nota.intomset10) FROM nota
				WHERE nota.intid_jpenjualan != 5 
				AND nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.intid_week = "'.$week.'" 
				and nota.intid_jpenjualan = 2 ) intomset10ChallHut,
				(SELECT SUM(nota.intomset20) FROM nota
				WHERE nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.intid_week = "'.$week.'"
				and nota.intid_jpenjualan = 2 )intomset20ChallHut,
				(SELECT SUM(nota.intomset10) FROM nota
				WHERE nota.intid_jpenjualan != 5 
				AND nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.intid_week = "'.$week.'" 
				and nota.intid_jpenjualan = 3 ) intomset10Challange,
				(SELECT SUM(nota.intomset20) FROM nota
				WHERE nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.intid_week = "'.$week.'"
				and nota.intid_jpenjualan = 3 )intomset20Challange,
				(SELECT SUM(nota.intomset10) FROM nota
				WHERE nota.intid_jpenjualan != 5 
				AND nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.intid_week = "'.$week.'" 
				and nota.intid_jpenjualan = 4 ) intomset10TradeIn,
				(SELECT SUM(nota.intomset20) FROM nota
				WHERE nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.intid_week = "'.$week.'"
				and nota.intid_jpenjualan = 4 )intomset20TradeIn,
				(SELECT SUM(nota.intomset10) FROM nota
				WHERE nota.intid_jpenjualan != 5 
				AND nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.intid_week = "'.$week.'" 
				and nota.intid_jpenjualan = 5 ) intomset101free1net,
				(SELECT SUM(nota.intomset20) FROM nota
				WHERE nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.intid_week = "'.$week.'"
				and nota.intid_jpenjualan = 5 )intomset201free1net,
				(SELECT SUM(nota.intomset10) FROM nota
				WHERE nota.intid_jpenjualan != 5 
				AND nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.intid_week = "'.$week.'" 
				and nota.intid_jpenjualan = 6 ) intomset101free110prs,
				(SELECT SUM(nota.intomset20) FROM nota
				WHERE nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.intid_week = "'.$week.'"
				and nota.intid_jpenjualan = 6 )intomset201free110prs,				
				(SELECT SUM(nota_detail.intquantity*nota_detail.intharga) 
				FROM nota INNER JOIN nota_detail ON nota.intid_nota = nota_detail.intid_nota INNER JOIN barang ON nota_detail.intid_barang = barang.intid_barang
				WHERE nota.intid_week = "'.$week.'"
				AND nota.intid_cabang = c.intid_cabang
				AND nota.intid_cabang != 1
				AND (nota.intid_jpenjualan = 5 OR nota.intid_jpenjualan = 7)) omsetnetto, 
				(SELECT SUM(nota_detail.intquantity*nota_detail.intharga) 
				FROM nota INNER JOIN nota_detail ON nota.intid_nota = nota_detail.intid_nota INNER JOIN barang ON nota_detail.intid_barang = barang.intid_barang
				WHERE nota.intid_week = "'.$week.'"
				AND nota.intid_cabang = c.intid_cabang
				AND nota.intid_cabang != 1
				AND nota.intid_jpenjualan = 11) omsetspecialprice,
				(SELECT SUM(nota_detail.intquantity*nota_detail.intharga) 
				FROM nota INNER JOIN nota_detail ON nota.intid_nota = nota_detail.intid_nota INNER JOIN barang ON nota_detail.intid_barang = barang.intid_barang
				WHERE nota.intid_week = "'.$week.'"
				AND nota.intid_cabang = c.intid_cabang
				AND nota.intid_jpenjualan = 12) omsetpoint,
				(SELECT sum(nota.inttotal_bayar) 
				FROM nota INNER JOIN nota_detail ON nota.intid_nota = nota_detail.intid_nota INNER JOIN barang ON nota_detail.intid_barang = barang.intid_barang
				WHERE nota.intid_week = "'.$week.'"
				AND nota.intid_cabang = c.intid_cabang
				AND nota.intid_jpenjualan = 10) omsetsk,
				(select sum(nota_detail.intquantity*nota_detail.intharga) 
				from nota, nota_detail, barang 
				where nota.intid_nota = nota_detail.intid_nota
				and nota_detail.intid_barang = barang.intid_barang
				and nota.intid_week = "'.$week.'"
				and nota.intid_cabang = c.intid_cabang
				and nota.is_arisan = 0
				and nota.is_dp = 0
				and barang.intid_jbarang=5) omsetlg,
				(select sum(nota_detail.intquantity*nota_detail.intharga) 
				from nota, nota_detail, barang 
				where nota.intid_nota = nota_detail.intid_nota
				and nota_detail.intid_barang = barang.intid_barang
				and nota.intid_week = "'.$week.'"
				and nota.intid_cabang = c.intid_cabang
				and barang.intid_jbarang=6
				and nota.is_arisan = 0
				and nota.is_dp = 0) omsetll,
				(select sum(inttotal_bayar) from nota where 
				nota.intid_cabang = c.intid_cabang
				and nota.intid_week = "'.$week.'") inttotal_bayar,
				(select sum(intpv) from nota where 
				nota.intid_cabang = c.intid_cabang
				and nota.intid_week = "'.$week.'") intpv,
			c.strnama_cabang 
			from cabang c';
		$query = $this->db->query($this->temp);
	return $query->result();
		}
	}
?>